package net.maku.quartz.task;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import net.maku.system.dao.SysLogLoginDao;
import net.maku.system.dao.SysLogOperateDao;
import net.maku.system.entity.SysLogLoginEntity;
import net.maku.system.entity.SysLogOperateEntity;
import net.maku.system.query.SysLogLoginQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.Calendar;
import java.util.Date;

/**
 * 测试定时任务
 *
 * @author mima0000

 */
@Slf4j
@Service
public class TestTask {

@Autowired
SysLogLoginDao sysLogLoginDao;
@Autowired
SysLogOperateDao sysLogOperateDao;


    private LambdaQueryWrapper<SysLogLoginEntity> getWrapper() {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date()); // 设置日历的时间为当前时间
        calendar.add(Calendar.DATE, -7); // 从当前时间减去30天
        Date sevenDaysAgo = calendar.getTime(); // 获取7天前的日期
        LambdaQueryWrapper<SysLogLoginEntity> wrapper = Wrappers.lambdaQuery();
        wrapper.lt( SysLogLoginEntity::getCreateTime,sevenDaysAgo );
        return wrapper;
    }

    private LambdaQueryWrapper<SysLogOperateEntity> getWrapper1() {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date()); // 设置日历的时间为当前时间
        calendar.add(Calendar.DATE, -7); // 从当前时间减去30天

        Date sevenDaysAgo = calendar.getTime(); // 获取7天前的日期
        LambdaQueryWrapper<SysLogOperateEntity> wrapper = Wrappers.lambdaQuery();
        wrapper.lt( SysLogOperateEntity::getCreateTime,sevenDaysAgo );
        return wrapper;
    }

    public void run(String params) {
        //删除登录日志还有操作日志 7天之前
        sysLogLoginDao.delete(getWrapper());
        sysLogOperateDao.delete(getWrapper1());
        log.info("执行删除日志成功");
    }


}
